package com.sne.airways.system.pojo;

import org.hibernate.annotations.BatchSize;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.GenericGenerator;

import javax.persistence.*;
import java.io.Serializable;

/**
 * Created with IntelliJ IDEA.
 * User: skyline{http://my.oschina.net/skyline520}
 * Date: 12-12-3
 * Time: 上午10:38
 * To change this template use File | Settings | File Templates.
 */
@Entity
@Table(name = "TD_USER_ROLE")
@BatchSize(size=5)
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class TdUserRole implements Serializable {
    private static final long serialVersionUID = 3129490214392725871L;
    /**
     * 关联ID
     */
    @Id
    @GeneratedValue(generator = "system-uuid")
    @GenericGenerator(name = "system-uuid",strategy = "uuid")
    @Column(name = "USERROLEID",length = 45)
    private String userRoleId;
    @ManyToOne(cascade ={CascadeType.PERSIST,CascadeType.MERGE},fetch=FetchType.LAZY)
    @JoinColumn(name = "USERID")
    private TdUser user;
    @ManyToOne(cascade ={CascadeType.PERSIST,CascadeType.MERGE},fetch=FetchType.LAZY)
    @JoinColumn(name = "ROLEID")
    private TdRole role;

    public String getUserRoleId() {
        return userRoleId;
    }

    public void setUserRoleId(String userRoleId) {
        this.userRoleId = userRoleId;
    }

    public TdUser getUser() {
        return user;
    }

    public void setUser(TdUser user) {
        this.user = user;
    }

    public TdRole getRole() {
        return role;
    }

    public void setRole(TdRole role) {
        this.role = role;
    }

    @Override
    public int hashCode() {
        return userRoleId != null ? userRoleId.hashCode() : 0;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) return true;
        if (!(obj instanceof TdUser)) return false;

        TdUserRole tdUserRole = (TdUserRole) obj;

        if (userRoleId != null ? !userRoleId.equals(tdUserRole.userRoleId) : tdUserRole.userRoleId != null) return false;

        return true;
    }
}
